package cn.poco.pepsi.util.xmlpared;

import java.io.InputStream;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;
import cn.poco.pepsi.bean.Discount;

public class GetDiscountByResIdXmlparse {
	private static Discount discountBean = null;

	public static Discount getXml(InputStream inSteam) throws Exception {
		XmlPullParser xmpparse = Xml.newPullParser();
		xmpparse.setInput(inSteam, "UTF-8");
		int code = xmpparse.getEventType();
		while (code != XmlPullParser.END_DOCUMENT) {
			switch (code) {
			case XmlPullParser.START_TAG:
				if ("discount".equals(xmpparse.getName())) {
					discountBean = new Discount();
				}
				if (discountBean != null) {
					if ("info-id".equals(xmpparse.getName())) {
						String key = xmpparse.nextText();
						discountBean.setDisID(Integer.parseInt(key));
					}
					if ("title".equals(xmpparse.getName())) {
						String key = xmpparse.nextText();
						discountBean.setDisTitle(key);
					}
					if ("content".equals(xmpparse.getName())) {
						String key = xmpparse.nextText();
						discountBean.setDisContent(key);
					}
					if ("photo".equals(xmpparse.getName())) {
						String key = xmpparse.nextText();
						discountBean.setDisPhoto(key);
					}
					if ("res-id".equals(xmpparse.getName())) {
						String key = xmpparse.nextText();
						discountBean.setResID(key);
					}
					if ("res-title".equals(xmpparse.getName())) {
						String key = xmpparse.nextText();
						discountBean.setResTitle(key);
					}
					if ("use-card".equals(xmpparse.getName())) {
						String key = xmpparse.nextText();
						discountBean.setUseCard(Integer.parseInt(key));
					}
					if ("use-sms".equals(xmpparse.getName())) {
						String key = xmpparse.nextText();
						discountBean.setUseSms(Integer.parseInt(key));
					}
					if ("is-pepsi".equals(xmpparse.getName())) {
						String key = xmpparse.nextText();
						discountBean.setUserPepsi(Integer.parseInt(key));
					}
				}
				break;
			}
			code = xmpparse.next();
		}
		inSteam.close();
		return discountBean;
	}

}
